package com.to8to.kitt.client;

import org.apache.thrift.TException;

import com.to8to.kitt.Advice;
import com.to8to.kitt.esb.client.ThriftClientPoolFactory;

/**
 * Thrift客户端工厂
 * @author Ervin.zhang
 * @date 2015年1月12日 下午10:03:51
 */
public class ThriftClientFactory {

//	private static Map<Class<?>, Object> serviceMap = new HashMap<Class<?>, Object>();
//
//	static
//	{
//		ThriftClientMonitor.start("/service/" + BusServer.class.getName());
//	}
	
	public static Object getClient(Class<?> service, ThriftClientConfig config , Advice advice) 
	{
		
		return ThriftClientPoolFactory.getClient(service);
		
//		synchronized (service) 
//		{
//			Object ifaceProxy = null;
//			if (serviceMap.containsKey(service))
//				ifaceProxy = serviceMap.get(service);
//			else 
//			{
//				ThriftClientInvocationHandler handler = new ThriftClientInvocationHandler(service.getName(), config, advice);
//				
//				ThriftClientMonitor.handlers.add(handler);
//				
//				Class<?> iface = null;
//				
//				Class<?>[] classes = service.getDeclaredClasses();
//				
//				for (Class<?> clz : classes) {
//					if (clz.getSimpleName().equals("Iface")) {
//						iface = clz;
//						break;
//					}
//				}
//
//				if(iface != null)
//				{
//					ifaceProxy = Proxy.newProxyInstance(ThriftClientFactory.class.getClassLoader(), new Class<?>[] { iface }, handler);
//					
//					serviceMap.put(service, ifaceProxy);
//				}
//			}
//			
//			return ifaceProxy;
//		}
	}
	
	public static Object getClient(Class<?> service, String host, int port, int timeoutMs, Advice advice) 
	{
		return ThriftClientPoolFactory.getClient(service);
		
//		return getClient(service, new ThriftClientConfig(null, host, port, timeoutMs), advice);
	}

	public static void main(String[] args) throws TException {

	}

}
